<template>
  <div class="choose-goods">
    <el-tabs v-model="activeValue" type="card" @tab-click="handleClick">
      <el-tab-pane
        v-for="(item,index) in pageTab"
        :key="index"
        :label="item.label"
        :name="item.value"
      >
      <el-select v-if="item.value === '3'" v-model="sceneTypeCode" filterable placeholder="请选择" @change="selectChange">
        <el-option v-for="item in selectList" :key="item.index" :label="item.label" :value="item.value" />
      </el-select>
        <evue-table :data="list" :option="option" @currentRowChange="currentRowChange" @paginationChance="pageCurrent" />
      </el-tab-pane>
      <!-- <el-tab-pane label="系统页面" name="first">
        <evue-table :data="list" :option="option" @currentRowChange="currentRowChange" />
      </el-tab-pane>
      <el-tab-pane label="自定义页面" name="second">
        <evue-table :data="list" :option="option" @currentRowChange="currentRowChange" />
      </el-tab-pane> -->
    </el-tabs>

  </div>
</template>
<script>
// import index from './index.js'
import { searchAllDictionaries } from '@/api/public'
import { getCanChoosePage,getActivityPage } from '@/api/shoppingMall/feature'
export default  {
  props: {
    isGetChooseData: { // 是否开始返回数据
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      selectList: [],
      sceneTypeCode: 'POINTS_MALLA_SCENE', // value: "积分商城":"POINTS_MALLA_SCENE"  "秒杀":"SECKILL_SCENE"
      activeValue: 0,
      pageParms: {
        pageNum: 1,
        pageSize: 10,
        type: 0,
        campaignScene: 'POINTS_MALLA_SCENE'
      },
      pageTab: '',
      list: [],
      option: {
        isPagination: true,
        isMenu: false,
        paginationTotal: 10,
        paginationCurrent: 1,
        paginationSize: 10,
        highlightCurrentRow: true,
        column: [
          {
            label: '名称',
            prop: 'title'
          },
          {
            label: '创建时间',
            prop: 'createTime'
          }
        ]
      },
      currentchooseFeatures: {}// 当前选择的
    }
  },
  created() {
    searchAllDictionaries({ type: 'page_type' }).then(res => {
      this.pageTab = res
      console.log('this.pageTab', this.pageTab)
    })
    searchAllDictionaries({ type: 'campaign_scene_for_cms_page' }).then(res => {
      this.selectList = res
    })
    // this.getPageList(this.pageParms.type)
    // for (let i = 0; i < 8; i++) {
    //   this.list.push({
    //     id: i,
    //     title: '微页面' + i,
    //     gtmTime: '2019-08-02 15:30:30'
    //   })
    // }
  },
  mounted () {
    this.getPageList(this.pageParms.type)
  },
  methods: {
    selectChange(){
      this.getPageList()
    },
    handleClick(tab, event) {
      this.pageParms.type = tab.name
      this.pageParms.pageNum = 1
        this.getPageList()
      console.log('tab.name', tab.name)
      console.log('event', event)
    },
    getPageList() {
      console.log('this.pageParms',this.pageParms.type)
      // this.pageParms.type = type
      if(this.pageParms.type === '3'){
        getActivityPage({...this.pageParms,campaignScene:this.sceneTypeCode}).then(res => {
          res.records.forEach(item => {
            item.title = item.name
            item.type = 3
          })
          this.list = res.records
          this.option.paginationTotal = res.total
        })
      }else{
        getCanChoosePage(this.pageParms).then(res => {
          this.list = res.records
          this.option.paginationTotal = res.total
        })
      }

    },
    /** 单选*/
    currentRowChange(ev) {
      // console.log('ev', ev)
      this.currentchooseFeatures = ev
      this.$emit('chooseChooseFeaturesFun', {
        data: this.currentchooseFeatures
      })
    },
    pageCurrent(val) {
      // console.log('val', val.data.current)
      this.pageParms.pageNum = val.data.current
      this.option.paginationCurrent = val.data.current
      this.pageParms.pageSize = val.data.size
      this.getPageList()
    }
  }
}
</script>
